﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;
using MisDLL;
using System.Data;

namespace MisBLL
{
    public class YTDAO : MarshalByRefObject, IYT
    {
        protected DbHelper dbHelper = new DbHelper();

        //根据编码查询钱款用途信息
        public MisModel.YT GetById(string id)
        {
            if (string.IsNullOrEmpty(id))
                return null;
            string sql = string.Format("select * from YT_TAB where YT_ID='{0}'", id);
            DataTable dt=  dbHelper.ExecuteDataTable(sql);
            MisModel.YT entity = null;
            if (dt != null && dt.Rows.Count > 0){
                entity = new MisModel.YT();
                entity.YtID = dt.Rows[0]["YT_ID"].ToString();
                entity.YtName = dt.Rows[0]["YT"].ToString();
                entity.F1 = dt.Rows[0]["F1"].ToString();
            }
            return entity;
        }

        //查询钱款用途列表
        public DataTable GetAll()
        {
            string sql = "select YT_ID,YT,F1,(YT_ID + '.' + YT) as ItemShow  from YT_TAB";
            return dbHelper.ExecuteDataTable(sql);
        }

        //添加钱款用途信息
        public int Add(MisModel.YT obj)
        {
            if (string.IsNullOrEmpty(obj.F1.ToString()))
            {
                obj.F1 = "Y";
            }
            string sql = string.Format("insert into YT_TAB(YT_ID,YT,F1) values('{0}','{1}','{2}')", obj.YtID, obj.YtName, obj.F1);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //修改钱款用途信息
        public int Update(MisModel.YT obj)
        {
            string sql = string.Format("update YT_TAB set YT='{0}',F1='{1}' where YT_ID='{2}'", obj.YtName, obj.F1, obj.YtID);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //根据ID删除钱款用途信息
        public int Delete(string id)
        {
            string sql = string.Format("delete from YT_TAB where YT_ID='{0}'", id);
            return dbHelper.ExecuteNonQuery(sql);
        }
    }
}
